package com.lu.statistics.controller;

import com.lu.statistics.common.config.ServerResponse;
import com.lu.statistics.entity.enums.FlowTaskCompleteEnum;
import com.lu.statistics.entity.enums.ProductTypeEnum;
import com.lu.statistics.entity.front.request.SelectGroupRequest;
import com.lu.statistics.entity.front.response.ProGroupResponse;
import com.lu.statistics.service.DishInfoService;
import com.lu.statistics.service.GroupService;
import com.lu.statistics.service.ProGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "分类模块", tags = {"分类模块"})
@RestController
@RequestMapping("/api/group")
public class ProGroupController {
    @Autowired
    private ProGroupService groupService;
    private final Map<ProductTypeEnum, GroupService> map = new HashMap<>();
    @Autowired
    public List<GroupService> serviceList;

    @PostConstruct
    void initMap() {
        serviceList.forEach(item -> map.put(item.getType(), item));
    }

    @ApiOperation(value = "商品分类列表", notes = "商品分类列表")
    @GetMapping(value = "/queryProGroupList")
    public ServerResponse<ProGroupResponse> queryGroupDishInfo(@RequestBody SelectGroupRequest request) {
        if (request.type.name().equals("ALL")) {
            ProGroupResponse group = new ProGroupResponse();
            //婚庆套餐
            ProGroupResponse wedding = groupService.queryPageWedding(request.getCurrent(), request.getPageSize());
            group.setWeddingTotal(wedding.getWeddingTotal());
            group.setWeddingList(wedding.getWeddingList());
            //婚庆主持人
            ProGroupResponse hostList = groupService.queryPageHostList(request.getCurrent(), request.getPageSize());
            group.setHostTotal(hostList.getHostTotal());
            group.setHostList(hostList.getHostList());
            //婚庆摄影师
            ProGroupResponse photographer = groupService.queryPagePhotographerList(request.getCurrent(), request.getPageSize());
            group.setPhotographerList(photographer.getPhotographerList());
            group.setPhotographerTotal(photographer.getPhotographerTotal());
            //婚庆歌手
            ProGroupResponse singer = groupService.queryPagePageSingerList(request.getCurrent(), request.getPageSize());
            group.setSingerList(singer.getSingerList());
            group.setSingerTotal(singer.getSingerTotal());
            //单选菜品
            ProGroupResponse dish = groupService.queryGroupDishList(request.getCurrent(), request.getPageSize());
            group.setCuisineList(dish.getCuisineList());
            group.setLiquorList(dish.getLiquorList());
            group.setDishTotal(dish.getDishTotal());
            //套餐菜品
            ProGroupResponse categories = groupService.queryDishDishCategories(request.getCurrent(), request.getPageSize());
            group.setCategorieList(categories.getCategorieList());
            group.setCgTotal(categories.getCgTotal());
            return ServerResponse.success(group);
        } else {
            ProGroupResponse groupResponse = map.get(request.getType()).queryGroupList(request.getCurrent(), request.getPageSize());
            return ServerResponse.success(groupResponse);
        }


    }
}
